package com.demo2do.fms.entity.vehicle.trailer;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.fms.entity.vehicle.ModifiedStatus;

/**
 * 挂车变更表
 * 
 * @author Wy
 *
 */
@Entity
@Table(name = "FMS_TRAILER_MODIFIED_VERSION")
public class TrailerModifiedVersion {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 变更状态 */
    @Enumerated(EnumType.STRING)
    private ModifiedStatus status;
    
    /** 版本号 */
    private int versionSorting;
    
    /** 挂车ID */
    private Long trailerId;
    
    /** 挂车主 */
    private String floorLord;
    
    /** 品牌 */
    private String brand;

    /** 挂车类型 */
    @Enumerated(EnumType.STRING)
    private TrailerType trailerType;
    
    /** 车辆类型（行驶证） */
    @Enumerated(EnumType.STRING)
    private TrailerVehicleType vehicleType;
    
    /** 挂车VIN码(后6位) */
    @Column(name = "VIN")
    private String vincode; 
    
    /** 满载量*/
    private BigDecimal trainload;
    
    /** 年审时间(挂车年检有效期至) 年月 */
    @DateTimeFormat(pattern = "yyyy-MM")
    private Date annualInspectionDate;
    
    /** 轴数 */
    private BigDecimal axles;
    
    /** 挂车行驶证 */
    private String drivingLicense;
    
    /** 第三方验证（挂车行驶副本扫描件） */
    private String drivingLicenseCopy;
    
    /** 45度角照片 */
    private String vehiclePhoto;

    @Column(name = "IS_DISABLED")
    private Boolean disabled;
    
    /**
     * The default constructor
     */
    public TrailerModifiedVersion() {
    }

    /**
     * @param trailer
     * @param versionSorting
     */
    public TrailerModifiedVersion(Trailer trailer, int versionSorting) {
        this.status = ModifiedStatus.AUDITING;
        this.trailerId = trailer.getId();
        this.versionSorting = versionSorting;
        this.disabled = false;
    }
    
    /**
     * @param trailer
     * @param newTrailer
     * @param versionSorting
     */
    public TrailerModifiedVersion(Trailer trailer, Trailer newTrailer, int versionSorting) {
        
        this.status = ModifiedStatus.AUDITING;
        this.trailerId = trailer.getId();
        this.versionSorting = versionSorting;
        this.disabled = false;
        
        this.floorLord = newTrailer.getFloorLord();
        this.trailerType = newTrailer.getTrailerType();
        this.vincode = newTrailer.getVincode();
        this.trainload = newTrailer.getTrainload();
        this.annualInspectionDate = newTrailer.getAnnualInspectionDate();
        this.brand = newTrailer.getBrand();
        this.axles = newTrailer.getAxles();
        this.vehicleType = newTrailer.getVehicleType();
        this.brand = newTrailer.getBrand();
        
        if (!StringUtils.equals(trailer.getDrivingLicense(), newTrailer.getDrivingLicense())) {
            this.drivingLicense = newTrailer.getDrivingLicense();
        }
        if (!StringUtils.equals(trailer.getDrivingLicenseCopy(), newTrailer.getDrivingLicenseCopy())) {
            this.drivingLicenseCopy = newTrailer.getDrivingLicenseCopy();
        }
        if (!StringUtils.equals(trailer.getVehiclePhoto(), newTrailer.getVehiclePhoto())) {
            this.vehiclePhoto = newTrailer.getVehiclePhoto();
        }
        
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the status
     */
    public ModifiedStatus getStatus() {
        return status;
    }

    /**
     * @return the versionSorting
     */
    public int getVersionSorting() {
        return versionSorting;
    }

    /**
     * @return the trailerId
     */
    public Long getTrailerId() {
        return trailerId;
    }

    /**
     * @return the floorLord
     */
    public String getFloorLord() {
        return floorLord;
    }
    
    /**
     * @return
     */
    public String getBrand() {
        return brand;
    }

    /**
     * @return the trailerType
     */
    public TrailerType getTrailerType() {
        return trailerType;
    }
    
    /**
     * @return
     */
    public TrailerVehicleType getVehicleType() {
        return vehicleType;
    }

    /**
     * @return the vincode
     */
    public String getVincode() {
        return vincode;
    }

    /**
     * @return the trainload
     */
    public BigDecimal getTrainload() {
        return trainload;
    }

    /**
     * @return
     */
    public Date getAnnualInspectionDate() {
        return annualInspectionDate;
    }
    
    /**
     * @return
     */
    public BigDecimal getAxles() {
        return axles;
    }

    /**
     * @return the drivingLicense
     */
    public String getDrivingLicense() {
        return drivingLicense;
    }

    /**
     * @return the drivingLicenseCopy
     */
    public String getDrivingLicenseCopy() {
        return drivingLicenseCopy;
    }
    
    /**
     * @return
     */
    public String getVehiclePhoto() {
        return vehiclePhoto;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(ModifiedStatus status) {
        this.status = status;
    }

    /**
     * @param versionSorting the versionSorting to set
     */
    public void setVersionSorting(int versionSorting) {
        this.versionSorting = versionSorting;
    }

    /**
     * @param trailerId the trailerId to set
     */
    public void setTrailerId(Long trailerId) {
        this.trailerId = trailerId;
    }

    /**
     * @param floorLord the floorLord to set
     */
    public void setFloorLord(String floorLord) {
        this.floorLord = floorLord;
    }
    
    /**
     * @param brand
     */
    public void setBrand(String brand) {
        this.brand = brand;
    }

    /**
     * @param trailerType the trailerType to set
     */
    public void setTrailerType(TrailerType trailerType) {
        this.trailerType = trailerType;
    }
    
    /**
     * @param vehicleType
     */
    public void setVehicleType(TrailerVehicleType vehicleType) {
        this.vehicleType = vehicleType;
    }

    /**
     * @param vincode the vincode to set
     */
    public void setVincode(String vincode) {
        this.vincode = vincode;
    }

    /**
     * @param trainload the trainload to set
     */
    public void setTrainload(BigDecimal trainload) {
        this.trainload = trainload;
    }

    /**
     * @param annualInspectionDate
     */
    public void setAnnualInspectionDate(Date annualInspectionDate) {
        this.annualInspectionDate = annualInspectionDate;
    }
    
    /**
     * @param axles
     */
    public void setAxles(BigDecimal axles) {
        this.axles = axles;
    }

    /**
     * @param drivingLicense the drivingLicense to set
     */
    public void setDrivingLicense(String drivingLicense) {
        this.drivingLicense = drivingLicense;
    }

    /**
     * @param drivingLicenseCopy the drivingLicenseCopy to set
     */
    public void setDrivingLicenseCopy(String drivingLicenseCopy) {
        this.drivingLicenseCopy = drivingLicenseCopy;
    }
    
    /**
     * @param vehiclePhoto
     */
    public void setVehiclePhoto(String vehiclePhoto) {
        this.vehiclePhoto = vehiclePhoto;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }
    
}